import java.util.Random;

public class Chance extends Block{
	private int chanceNumber;
	private int chanceMoney;
	private boolean isKeyUsed = false;
	
/////////////////////////////////////////////////////////
	//CONSTRUCTOR//
//////////////////////////////////////////////////////////
	
	public Chance(String name, int location){
		super(name, location);
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GETTERS AND SETTERS//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public void setKeyUsed(boolean isKeyUsed) {
		this.isKeyUsed = isKeyUsed;
	}

	public boolean isKeyUsed() {
		return isKeyUsed;
	}

	public void setChanceMoney(int chanceMoney) {
		this.chanceMoney = chanceMoney;
	}

	public int getChanceMoney() {
		return chanceMoney;
	}

	public void setChanceNumber(int chanceNumber) {
	this.chanceNumber = chanceNumber;
	}

	public int getChanceNumber() {
	return chanceNumber;
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FUNCTIONS//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public int shuffleChanceCards(){ //shuffle chance cards
		Random random = new Random();
		chanceNumber=random.nextInt(16)+1;
		return chanceNumber;
	}
	
	public void getChanceAction(Player[] orderedPlayer, int numberOfPlayers, int numberOfAlivePlayers, int counter, int chanceNum){
		switch(chanceNum){
			case 1:
				chance1(orderedPlayer, numberOfPlayers, numberOfAlivePlayers, counter);
				break;
			case 2:
				chance2(orderedPlayer, counter);
				break;
			case 3:
				chance3(orderedPlayer, counter);
				break;
			case 4:
				chance4(orderedPlayer, counter);
				break;
			case 5:
				chance5(orderedPlayer, counter);
				break;
			case 6:
				chance6(orderedPlayer, counter);
				break;
			case 7:
				chance7(orderedPlayer, counter);
				break;
			case 8:
				chance8(orderedPlayer, counter);
				break;
			case 9:
				chance9(orderedPlayer, counter);
				break;
			case 10:
				chance10(orderedPlayer, counter);
				break;
			case 11:
				chance11(orderedPlayer, counter);
				break;
			case 12:
				chance12(orderedPlayer, counter);
				break;
			case 13:
				chance13(orderedPlayer, counter);
				break;
			case 14:
				chance14(orderedPlayer, counter);
				break;
			case 15:
				chance15(orderedPlayer, counter);
				break;
			case 16:
				chance16(orderedPlayer, counter);
				break;
		}		
	}
	
	public void chance1(Player[] orderedPlayer, int numberOfPlayers, int numberOfAlivePlayers, int counter){
		orderedPlayer[counter].setMoney((orderedPlayer[counter].getMoney())-(numberOfAlivePlayers*500000));
		
		for(int i=0;i!=numberOfPlayers;i++){
			if(orderedPlayer[i].isAlive())
			orderedPlayer[i].setMoney((orderedPlayer[i].getMoney())+500000);
		}
	}
	public void chance2(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(33);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(18);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(4);
	}
	public void chance3(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setTotalSteps(3);
		orderedPlayer[counter].setBackwards(true);
	}
	public void chance4(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(17);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(2);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(28);
	}
	public void chance5(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(4);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(29);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(15);
	}
	
	public void chance6(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setHasChanceKey(true);
	}
	
	public void chance7(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(38);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(23);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(9);
	}
	
	public void chance8(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setMoney((orderedPlayer[counter].getMoney())-150000);
	}
	
	public void chance9(Player[] orderedPlayer, int counter){
			orderedPlayer[counter].setMoney(orderedPlayer[counter].getMoney()-(250000*orderedPlayer[counter].getNumberOfHouses()));
			orderedPlayer[counter].setMoney(orderedPlayer[counter].getMoney()-(1000000*orderedPlayer[counter].getNumberOfHotels()));
	}
	
	public void chance10(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setMoney((orderedPlayer[counter].getMoney())+1500000);
	}
	
	public void chance11(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setUtilityCursed(true);
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(5);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(6);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(16);
	}
	public void chance12(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setAirportCursed(true);
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(8);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(3);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(9);
	}
	public void chance13(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setAirportCursed(true);
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(8);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(3);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(9);
	}
	public void chance14(Player[] orderedPlayer, int counter){
		if(orderedPlayer[counter].getPosition()==7)
			orderedPlayer[counter].setTotalSteps(32);
		if(orderedPlayer[counter].getPosition()==22)
			orderedPlayer[counter].setTotalSteps(17);
		if(orderedPlayer[counter].getPosition()==36)
			orderedPlayer[counter].setTotalSteps(3);
	}
	public void chance15(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setJailed(true);
	}
	public void chance16(Player[] orderedPlayer, int counter){
		orderedPlayer[counter].setMoney((orderedPlayer[counter].getMoney())+500000);
	}
}
	